package com.example.visitmanage

import android.annotation.SuppressLint
import android.graphics.Color
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.visitmanage.databinding.ActivityVisitManageBinding
import com.example.lib_base.mvvm.BaseActivity
import com.example.visitmanage.adapter.VisisterAdapter
import com.example.visitmanage.viewmodel.VisitManagerViewModel
import dagger.hilt.android.AndroidEntryPoint


@Route(path = "/visitmanage/VisitManageActivity")
@AndroidEntryPoint
class VisitManageActivity : BaseActivity<ActivityVisitManageBinding, VisitManagerViewModel>() {
    lateinit var visisterAdapter:VisisterAdapter
    override fun onResume() {
        super.onResume()
        binding.btnAll.setBackgroundColor(Color.BLUE)
        binding.btnAl.setBackgroundColor(Color.GRAY)
        binding.btnPassed.setBackgroundColor(Color.GRAY)
        binding.btnRefused.setBackgroundColor(Color.GRAY)
        binding.btnFinish.setBackgroundColor(Color.GRAY)
        vm.getVisister()
    }


    override fun initView() {
        visisterAdapter = VisisterAdapter()
        binding.rvVisister.adapter=visisterAdapter
        binding.rvVisister.layoutManager= LinearLayoutManager(this)

        binding.back.setOnClickListener {
            finish()
        }
        binding.addVisit.setOnClickListener {
            ARouter.getInstance().build("/visitmanage/AddVisisterActivity").navigation()
        }
        binding.btnAll.setOnClickListener {
            binding.btnAll.setBackgroundColor(Color.BLUE)
            binding.btnAl.setBackgroundColor(Color.GRAY)
            binding.btnPassed.setBackgroundColor(Color.GRAY)
            binding.btnRefused.setBackgroundColor(Color.GRAY)
            binding.btnFinish.setBackgroundColor(Color.GRAY)
            vm.getVisister()
        }
        binding.btnAl.setOnClickListener {
            binding.btnAll.setBackgroundColor(Color.GRAY)
            binding.btnAl.setBackgroundColor(Color.BLUE)
            binding.btnPassed.setBackgroundColor(Color.GRAY)
            binding.btnRefused.setBackgroundColor(Color.GRAY)
            binding.btnFinish.setBackgroundColor(Color.GRAY)
            vm.getVisisterByStatus("待审核")
        }
        binding.btnPassed.setOnClickListener {
            binding.btnAll.setBackgroundColor(Color.GRAY)
            binding.btnAl.setBackgroundColor(Color.GRAY)
            binding.btnPassed.setBackgroundColor(Color.BLUE)
            binding.btnRefused.setBackgroundColor(Color.GRAY)
            binding.btnFinish.setBackgroundColor(Color.GRAY)
            vm.getVisisterByStatus("已通过")
        }
        binding.btnRefused.setOnClickListener {
            binding.btnAll.setBackgroundColor(Color.GRAY)
            binding.btnAl.setBackgroundColor(Color.GRAY)
            binding.btnPassed.setBackgroundColor(Color.GRAY)
            binding.btnRefused.setBackgroundColor(Color.BLUE)
            binding.btnFinish.setBackgroundColor(Color.GRAY)
            vm.getVisisterByStatus("已拒绝")
        }
        binding.btnFinish.setOnClickListener {
            binding.btnAll.setBackgroundColor(Color.GRAY)
            binding.btnAl.setBackgroundColor(Color.GRAY)
            binding.btnPassed.setBackgroundColor(Color.GRAY)
            binding.btnRefused.setBackgroundColor(Color.GRAY)
            binding.btnFinish.setBackgroundColor(Color.BLUE)
            vm.getVisisterByStatus("已完成")
        }
    }
    override fun initData() {
        vm.visisterSuccess.observe(this){
            visisterAdapter.data.clear()
            visisterAdapter.data.addAll(it.sortedByDescending { item -> item.id })
            visisterAdapter.notifyDataSetChanged()
        }
        vm.visisterSucces.observe(this){
            visisterAdapter.data.clear()
            visisterAdapter.data.addAll(it.sortedByDescending { item -> item.id })
            visisterAdapter.notifyDataSetChanged()
        }
    }
}